package com.caifu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caifu.bean.PageDo;
import com.caifu.bean.Result;
import com.caifu.bean.ResultUtil;
import com.caifu.controller.AbstractController;
import com.caifu.enums.LabelTypeEnum;
import com.caifu.enums.ShopPropertyEnum;
import com.caifu.mapper.*;
import com.caifu.pojo.*;
import com.caifu.util.AesUtil;
import com.caifu.util.CheckUtil;
import com.caifu.util.DateUtil;
import com.caifu.util.TreeUtils;
import com.caifu.vo.ShopPageVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

/**
 * ClassName : ShopService
 *
 * @author :  yb
 * @description ：
 * @date : 2021-03-04 10:49
 */
@Service
public class ShopService extends AbstractController {

    @Resource
    private YsLabelMapper ysLabelMapper;
    @Resource
    private YsShopMapper ysShopMapper;
    @Resource
    private SysOrganizationMapper sysOrganizationMapper;
    @Resource
    private SysOrganizationService sysOrganizationService;
    @Resource
    private SysUserMapper sysUserMapper;
    @Resource
    private YsShopLicenceMapper ysShopLicenceMapper;
    @Resource
    private YsShopLicenceImgMapper ysShopLicenceImgMapper;


    /**
     * 获取Excel导入记录列表
     *
     * @param vo vo
     * @return Result
     */
    public Result<Object> getShopListPage(ShopPageVO vo) {

        QueryWrapper<YsShop> queryWrapper = new QueryWrapper<>();
        //放入查询条件
        setQueryParamOfShopPage(queryWrapper, vo);

        IPage<YsShop> shopPage = ysShopMapper.selectPage(new Page<>(vo.getCurrentPage(), vo.getPageSize()), queryWrapper);

        List<YsShop> shopList = shopPage.getRecords();
        //数据处理- 页面展示
        transformDataForPage(shopList);

        return ResultUtil.getPageDataSuccess(new PageDo<>(vo.getCurrentPage(), vo.getPageSize(), shopPage.getTotal(), shopList));
    }


    private void setQueryParamOfShopPage(QueryWrapper<YsShop> queryWrapper, ShopPageVO vo) {

        //状态 1-有效 2-关闭 9-删除
        if (CheckUtil.isNull(vo.getState())) {
            queryWrapper.eq("state", "1");
        } else {
            queryWrapper.eq("state", vo.getState());
        }

        //组织架构id
        if (CheckUtil.isNotNull(vo.getOrgId())) {
            //查询下面的所有组织
            queryWrapper.in("org_id", Arrays.asList(getOrgIds(vo.getOrgId()).split(",")));
        } else {
            //---------如果没传组织进来 就按照 权限-------------
            //获取用户权限的组织架构
            List<SysOrganization> organizations = sysOrganizationService.getOrgList(getSysUser());
            List<String> orgIds = new ArrayList<>();
            getOrgListTwo(orgIds, organizations);
            queryWrapper.in("org_id", orgIds);
        }

        // 经营状态
        if (CheckUtil.isNotNull(vo.getManagementStatus())) {
            queryWrapper.eq("management_status", vo.getManagementStatus());
        }
        // 经营业态
        if (CheckUtil.isNotNull(vo.getBusinessType())) {
            queryWrapper.eq("business_type", vo.getBusinessType());
        }
        // 商铺标签
        if (CheckUtil.isNotNull(vo.getShopType())) {
            queryWrapper.like("shop_type", vo.getShopType());
        }
        //商铺名称
        if (CheckUtil.isNotNull(vo.getSearchShopName())) {
            queryWrapper.like("shop_name", vo.getSearchShopName());
        }
        //地址
        if (CheckUtil.isNotNull(vo.getSearchAddress())) {
            queryWrapper.like("address", vo.getSearchAddress());
        }

        //登记时间类型  1-本月 2-最近三个月 3-本年
        if (CheckUtil.isNotNull(vo.getRegisterTimeType())) {
            setShopTimeTypeParams(vo.getRegisterTimeType(), "create_time", queryWrapper);
        }
        //登记时间类型 -手选
        if (CheckUtil.isNotNull(vo.getRegisterTime())) {
            setShopTimeParams(vo.getRegisterTime(), "create_time", queryWrapper);
        }
        //关闭时间Type
        if (CheckUtil.isNotNull(vo.getCloseTimeType())) {
            setShopTimeTypeParams(vo.getCloseTimeType(), "close_time", queryWrapper);
        }

        //关闭时间-手选
        if (CheckUtil.isNotNull(vo.getCloseTime())) {
            setShopTimeParams(vo.getCloseTime(), "close_time", queryWrapper);

        }

    }

    private void setShopTimeTypeParams(Integer timeType, String queryField, QueryWrapper<YsShop> queryWrapper) {
        String firstDay = "";
        String lastDay = "";
        //本月
        if (timeType == 1) {
            LocalDateTime localDate = LocalDateTime.now();
            LocalDateTime localFirst = localDate.with(TemporalAdjusters.firstDayOfMonth());
            LocalDateTime localLast = localDate.with(TemporalAdjusters.lastDayOfMonth());
            firstDay = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00").format(localFirst);
            lastDay = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59").format(localLast);
        }
        //最近三个月
        int latelyThreeMonth = 2;
        if (timeType == latelyThreeMonth) {
            firstDay = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00").format(LocalDate.now().plusMonths(-3));
            lastDay = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59").format(LocalDate.now());
        }
        //本年
        int thisYear = 3;
        if (timeType == thisYear) {
            LocalDate firstDayOfYear = LocalDate.now().with(TemporalAdjusters.firstDayOfYear());
            LocalDate lastDayOfYear = LocalDate.now().with(TemporalAdjusters.lastDayOfYear());
            firstDay = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00").format(firstDayOfYear);
            lastDay = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59").format(lastDayOfYear);
        }
        if (CheckUtil.isNotNull(firstDay) && CheckUtil.isNotNull(lastDay)) {
            queryWrapper.between(queryField, firstDay, lastDay);
        }
    }


    private void setShopTimeParams(String time, String queryField, QueryWrapper<YsShop> queryWrapper) {
        String[] arr = time.split("~");
        String firstDay = arr[0].trim() + " 00:00:00";
        String lastDay = arr[1].trim() + " 23:59:59";
        queryWrapper.between(queryField, firstDay, lastDay);


    }


    private void transformDataForPage(List<YsShop> shopList) {
        shopList.forEach(shop -> {
            //经营状态
            if (CheckUtil.isNotNull(shop.getManagementStatus())) {
                shop.setManagementStatus(getLabelNames(getYsLabelList(LabelTypeEnum.JYZT.getKey()), shop.getManagementStatus()));
            }
            //经营业态
            if (CheckUtil.isNotNull(shop.getBusinessType())) {
                shop.setBusinessType(getLabelNames(getYsLabelList(LabelTypeEnum.JYYT.getKey()), shop.getBusinessType()));
            }
            //商铺标签
            if (CheckUtil.isNotNull(shop.getShopType())) {
                shop.setShopType(getLabelNames(getYsLabelList(LabelTypeEnum.SPBQ.getKey()), shop.getShopType()));
            }
            //创建人
            if (CheckUtil.isNotNull(shop.getCreateUserId())) {
                shop.setSysUserName(sysUserMapper.selectById(shop.getCreateUserId()).getUserName());
            }
            //关闭人
            if (CheckUtil.isNotNull(shop.getCloseUserId())) {
                shop.setCloseUserName(sysUserMapper.selectById(shop.getCloseUserId()).getUserName());
            }
            if (CheckUtil.isNotNull(shop.getCloseTime())) {
                String time = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDateTime.ofInstant(shop.getCloseTime().toInstant(), ZoneId.systemDefault()));
                shop.setCloseTimeForPage(time);
            }
        });
    }


    /**
     * 删除 商铺
     *
     * @param id id
     */
    public Result<Object> deleteShop(String id) {
        YsShop shop = ysShopMapper.selectById(id);
        if (CheckUtil.isNull(shop)) {
            return ResultUtil.errorMsg("商铺不存在");
        }
        shop.setState(9);
        ysShopMapper.updateById(shop);
        return ResultUtil.success();
    }

    /**
     * 关闭 商铺
     *
     * @param id id
     */
    public Result<Object> closeShop(String id) {
        YsShop shop = ysShopMapper.selectById(id);
        if (CheckUtil.isNull(shop)) {
            return ResultUtil.errorMsg("商铺不存在");
        }
        //状态 1-有效 2-无效 8-关闭 9-删除
        shop.setState(8);
        shop.setCloseTime(new Date());
        shop.setCloseUserId(getSysUser().getId());
        ysShopMapper.updateById(shop);
        return ResultUtil.success();
    }


    /**
     * 获取 所有的 orgId 逗号分隔
     *
     * @param orgId orgId
     * @return String
     */
    private String getOrgIds(String orgId) {
        SysOrganization organization = sysOrganizationMapper.selectById(orgId);
        getChildOrganization(organization);
        //获取全部 orgId
        List<String> orgList = new ArrayList<>();
        orgList.add(organization.getId() + "");
        if (CheckUtil.isNotNull(organization.getChildren())) {
            getOrgList(orgList, organization.getChildren());
        }
        return String.join(",", orgList);
    }

    /**
     * 查询下面的所有组织架构
     *
     * @param organization organization
     */
    private void getChildOrganization(SysOrganization organization) {

        QueryWrapper<SysOrganization> organizationQueryWrapper = new QueryWrapper<>();
        organizationQueryWrapper.eq("pid", organization.getId());
        organizationQueryWrapper.eq("status", "1");
        List<SysOrganization> orgList = sysOrganizationMapper.selectList(organizationQueryWrapper);
        if (CheckUtil.isNotNull(orgList) && orgList.size() > 0) {
            orgList.forEach(this::getChildOrganization);
        }
        organization.setChildren(orgList);
    }

    /**
     * 获取 组织架构下的  全部 orgId
     *
     * @param orgList      orgList
     * @param organization organization
     */
    private void getOrgList(List<String> orgList, List<SysOrganization> organization) {
        organization.forEach(org -> {
            orgList.add(org.getId() + "");
            if (CheckUtil.isNotNull(org.getChildren())) {
                getOrgList(orgList, org.getChildren());
            }
        });
    }

    /**
     * 获取 组织架构下的  全部 orgId
     *
     * @param orgList      orgList
     * @param organization organization
     */
    private void getOrgListTwo(List<String> orgList, List<SysOrganization> organization) {
        organization.forEach(org -> {
            orgList.add(org.getId() + "");
            if (CheckUtil.isNotNull(org.getSysOrganizations())) {
                getOrgListTwo(orgList, org.getSysOrganizations());
            }
        });
    }


    /**
     * id 获取 标签 names
     *
     * @param labelList labelList
     * @param labelIds  labelIds
     * @return return
     */
    private String getLabelNames(List<YsLabel> labelList, String labelIds) {
        String[] arr = labelIds.split(",");
        List<String> labelNames = new ArrayList<>();
        for (String s : arr) {
            if (CheckUtil.isNotNull(s)) {
                for (YsLabel label : labelList) {
                    if (label.getId().equals(Integer.parseInt(s))) {
                        labelNames.add(label.getLabelName());

                    }
                }
            }
        }
        return String.join(",", labelNames);
    }


    /**
     * 获取标签
     *
     * @param pid pid 父节点
     * @return List
     */
    public List<YsLabel> getYsLabelList(String pid) {
        QueryWrapper<YsLabel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", pid);
        queryWrapper.eq("status", "1");
        return ysLabelMapper.selectList(queryWrapper);
    }


    /**
     * 添加 商铺
     *
     * @param shop shop
     * @return Result
     */
    public Result<Object> addShop(YsShop shop) throws Exception {

        List<SysOrganization> sysOrganizations = sysOrganizationMapper.selectList(null);
        if (!TreeUtils.isEndNode(sysOrganizations, Integer.parseInt(shop.getOrgId()))) {
            return ResultUtil.errorMsg("所在地区请选择末节点");
        }

        QueryWrapper<YsShop> shopQueryWrapper = new QueryWrapper<>();
        shopQueryWrapper.eq("shop_name", shop.getShopName());
        shopQueryWrapper.eq("address", shop.getAddress());
        YsShop isExistShop = ysShopMapper.selectOne(shopQueryWrapper);
        if (CheckUtil.isNotNull(isExistShop)) {
            return ResultUtil.errorMsg("商铺名称商铺地址不允许重复");
        }

        shop.setCreateTime(new Date());
        shop.setCreateUserId(getSysUser().getId());
        //状态 1-有效 2-关闭 9-删除
        shop.setState(1);
        //-------------加密---------------------
        encryptShop(shop);

        ysShopMapper.insert(shop);
        return ResultUtil.success();
    }


    /**
     * 修改 商铺
     *
     * @param shop shop
     * @return Result
     */
    public Result<Object> updateShop(YsShop shop) throws Exception {
        YsShop oldShop = ysShopMapper.selectById(shop.getId());
        if (CheckUtil.isNull(oldShop)) {
            return ResultUtil.errorMsg("未查询到此商铺");
        }

        List<SysOrganization> sysOrganizations = sysOrganizationMapper.selectList(null);
        if (!TreeUtils.isEndNode(sysOrganizations, Integer.parseInt(shop.getOrgId()))) {
            return ResultUtil.errorMsg("所在地区请选择末节点");
        }

        shop.setCreateTime(oldShop.getCreateTime());
        shop.setUpdateTime(new Date());
        shop.setCreateUserId(oldShop.getCreateUserId());
        //状态 1-有效 2-关闭 9-删除
        shop.setState(oldShop.getState());
        //加密
        encryptShop(shop);

        ysShopMapper.updateById(shop);
        return ResultUtil.success();
    }

    /**
     * 加密
     *
     * @param shop shop
     * @throws Exception Exception
     */
    private void encryptShop(YsShop shop) throws Exception {
        //-------------加密---------------------
        if (CheckUtil.isNotNull(shop.getPropertyUserPid())) {
            shop.setPropertyUserPid(AesUtil.Encrypt(shop.getPropertyUserPid()));
        }
        if (CheckUtil.isNotNull(shop.getPhone())) {
            shop.setPhone(AesUtil.Encrypt(shop.getPhone()));
        }
        if (CheckUtil.isNotNull(shop.getUserPid())) {
            shop.setUserPid(AesUtil.Encrypt(shop.getUserPid()));
        }
    }


    public YsShop getShop(String id) throws Exception {
        YsShop ysShop = ysShopMapper.selectById(id);
        //解密
        decryptShopParam(ysShop);
        SysOrganization sysOrganization = sysOrganizationMapper.selectById(ysShop.getOrgId());
        ysShop.setOrgName(sysOrganization.getName());


        getLicenceImg(ysShop);
        return ysShop;
    }


    /**
     * 获取证照
     *
     * @param ysShop ysShop
     */
    private void getLicenceImg(YsShop ysShop) {
        //获取图片
        QueryWrapper<YsShopLicence> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("shop_id", ysShop.getId());
        queryWrapper.eq("state", "1");
        queryWrapper.orderByDesc("create_time");
        List<YsShopLicence> shopLicenceList = ysShopLicenceMapper.selectList(queryWrapper);
        shopLicenceList.forEach(model -> {
            model.setLicenceType(getLabelNames(getYsLabelList(LabelTypeEnum.ZZLX.getKey()), model.getLicenceType()));
            String today = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00").format(LocalDateTime.now());

            try {
                //判断是否生效中
                int day = DateUtil.daysBetween(today, model.getValidityTime() + " 00:00:00");
                if (day >= 0) {
                    model.setIsEffective(1);
                } else {
                    model.setIsEffective(2);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if ("1".equals(model.getValidityType())) {
                model.setValidityType("有效期限");
            } else if ("2".equals(model.getValidityType())) {
                model.setValidityType("永久(无期限)");
            }


            QueryWrapper<YsShopLicenceImg> imgQueryWrapper = new QueryWrapper<>();
            imgQueryWrapper.eq("licence_id", model.getId());
            List<YsShopLicenceImg> shopLicenceImgList = ysShopLicenceImgMapper.selectList(imgQueryWrapper);
            if (CheckUtil.isNotNull(shopLicenceImgList) && shopLicenceImgList.size() > 0) {
                List<String> imgList = new ArrayList<>();
                shopLicenceImgList.forEach(img -> imgList.add(img.getImgUrl()));
                model.setImageArr(imgList.toArray(new String[0]));
            }
        });

        //放入证照
        ysShop.setShopLicence(shopLicenceList);
    }


    /**
     * 获取 商铺 详情
     *
     * @param id id
     * @return YsShop
     */
    public YsShop getShopDetailById(String id) throws Exception {
        YsShop ysShop = ysShopMapper.selectById(id);
        //解密
        decryptShopParam(ysShop);

        //经营业态
        if (CheckUtil.isNotNull(ysShop.getBusinessType())) {
            List<YsLabel> getBusinessTypeList = getYsLabelList(LabelTypeEnum.JYYT.getKey());
            ysShop.setBusinessType(getLabelNames(getBusinessTypeList, ysShop.getBusinessType()));
        }
        //商铺标签
        if (CheckUtil.isNotNull(ysShop.getShopType())) {
            List<YsLabel> getShopTypeList = getYsLabelList(LabelTypeEnum.SPBQ.getKey());
            ysShop.setShopType(getLabelNames(getShopTypeList, ysShop.getShopType()));
        }
        //所在地区
        if (CheckUtil.isNotNull(ysShop.getOrgId())) {
            ysShop.setOrgId(getWholeOrgName(ysShop.getOrgId()));
        }
        //产权人
        if (CheckUtil.isNotNull(ysShop.getShopProperty())) {
            ysShop.setShopProperty(ShopPropertyEnum.getName(ysShop.getShopProperty()));
        }
        //关闭时间
        if (CheckUtil.isNotNull(ysShop.getCloseTime())) {
            String time = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.ofInstant(ysShop.getCloseTime().toInstant(), ZoneId.systemDefault()));
            ysShop.setCloseTimeForPage(time);
        }
        //关闭人
        if (CheckUtil.isNotNull(ysShop.getCloseUserId())) {
            ysShop.setCloseUserName(sysUserMapper.selectById(ysShop.getCloseUserId()).getUserName());
        }

        //证照管理
        getLicenceImg(ysShop);
        return ysShop;
    }


    /**
     * 获取 完整的 组织 name
     *
     * @param orgId orgId
     */
    private String getWholeOrgName(String orgId) {
        List<String> orgNameList = new LinkedList<>();
        getOrgName(orgNameList, orgId);
        String orgName = "";
        for (int i = orgNameList.size(); i > 0; i--) {
            if (CheckUtil.isNotNull(orgName)) {
                orgName += ">" + orgNameList.get(i - 1);
            } else {
                orgName += orgNameList.get(i - 1);
            }
        }

        return orgName;
    }

    private void getOrgName(List<String> orgNameList, String orgId) {
        if (CheckUtil.isNull(orgNameList)) {
            orgNameList = new LinkedList<>();
        }
        SysOrganization sysOrganization = sysOrganizationMapper.selectById(orgId);
        if (CheckUtil.isNotNull(sysOrganization)) {
            orgNameList.add(sysOrganization.getName());

            if (CheckUtil.isNotNull(sysOrganization.getPid())) {
                getOrgName(orgNameList, sysOrganization.getPid() + "");
            }
        }

    }

    /**
     * 解密
     *
     * @param ysShop ysShop
     * @throws Exception Exception
     */
    private void decryptShopParam(YsShop ysShop) throws Exception {
        //身份证号
        if (CheckUtil.isNotNull(ysShop.getUserPid())) {
            ysShop.setUserPid(AesUtil.Decrypt(ysShop.getUserPid()));
        }
        //手机号
        if (CheckUtil.isNotNull(ysShop.getPhone())) {
            ysShop.setPhone(AesUtil.Decrypt(ysShop.getPhone()));
        }
        //产权人身份证
        if (CheckUtil.isNotNull(ysShop.getPropertyUserPid())) {
            ysShop.setPropertyUserPid(AesUtil.Decrypt(ysShop.getPropertyUserPid()));
        }

    }


    /**
     * 添加 商铺 证照信息
     *
     * @param shopLicence shopLicence
     * @return Result
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public Result<Object> addOrUpdateShopLicence(YsShopLicence shopLicence) {

        if (CheckUtil.isNull(shopLicence.getShopId())) {
            return ResultUtil.errorMsg("未查询到此商铺");
        }
        //没有Id就是添加 有的话就是修改
        if (CheckUtil.isNull(shopLicence.getId())) {
            addShopLicence(shopLicence);
        } else {
            updateShopLicence(shopLicence);
        }

        return ResultUtil.success();
    }

    private void addShopLicence(YsShopLicence shopLicence) {
        shopLicence.setCreateTime(new Date());
        shopLicence.setUpdateTime(new Date());
        shopLicence.setState(1);
        ysShopLicenceMapper.insert(shopLicence);
        //放图片
        if (CheckUtil.isNotNull(shopLicence.getImageArr())) {
            Arrays.asList(shopLicence.getImageArr()).forEach(img -> {
                YsShopLicenceImg licenceImg = new YsShopLicenceImg();
                licenceImg.setImgUrl(img);
                licenceImg.setLicenceId(shopLicence.getId());
                ysShopLicenceImgMapper.insert(licenceImg);
            });
        }
    }

    private void updateShopLicence(YsShopLicence shopLicence) {
        YsShopLicence old = ysShopLicenceMapper.selectById(shopLicence.getId());
        shopLicence.setState(old.getState());

        shopLicence.setCreateTime(old.getCreateTime());
        shopLicence.setUpdateTime(new Date());
        ysShopLicenceMapper.updateById(shopLicence);


        //图片先删除在添加
        QueryWrapper<YsShopLicenceImg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("licence_id", shopLicence.getId());
        ysShopLicenceImgMapper.delete(queryWrapper);

        //放图片
        if (CheckUtil.isNotNull(shopLicence.getImageArr())) {
            Arrays.asList(shopLicence.getImageArr()).forEach(img -> {
                YsShopLicenceImg licenceImg = new YsShopLicenceImg();
                licenceImg.setImgUrl(img);
                licenceImg.setLicenceId(shopLicence.getId());
                ysShopLicenceImgMapper.insert(licenceImg);
            });
        }
    }


    /**
     * 删除 证照
     *
     * @return Result
     */
    public Result<Object> deleteLicence(String id) {

        if (CheckUtil.isNull(id)) {
            return ResultUtil.errorMsg("未查询到此条数据");
        }
        YsShopLicence shopLicence = ysShopLicenceMapper.selectById(id);
        shopLicence.setState(9);
        shopLicence.setUpdateTime(new Date());
        ysShopLicenceMapper.updateById(shopLicence);
//        QueryWrapper<YsShopLicenceImg> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("licence_id", id);
//        ysShopLicenceImgMapper.delete(queryWrapper);
        return ResultUtil.success();
    }

    /**
     * 获取 证照
     *
     * @return Result
     */
    public Result<Object> getLicenceById(String id) {

        if (CheckUtil.isNull(id)) {
            return ResultUtil.errorMsg("未查询到此条数据");
        }
        YsShopLicence shopLicence = ysShopLicenceMapper.selectById(id);

        QueryWrapper<YsShopLicenceImg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("licence_id", id);
        List<YsShopLicenceImg> imgList = ysShopLicenceImgMapper.selectList(queryWrapper);

        List<String> img = new ArrayList<>();
        imgList.forEach(model -> img.add(model.getImgUrl()));
        shopLicence.setImageArr(img.toArray(new String[0]));


        return ResultUtil.getDataSuccess(shopLicence);
    }


}
